<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/11
 * Time: 16:59
 */
namespace app\web\controller;

use app\web\service\PrintService;
use app\BaseController;
use think\facade\Log;

class PrintSearch extends Base{
    /**
     * @todo 打印查询
     * @author YangFan
     */
    public function PrintSearch(){
        if($this->request->ispost()){
            // $user=request()->user;//登录信息
            // $shop_id = empty($user['id'])?0:$user['id'];//店铺ID
            // if(empty($shop_id) || !is_numeric($shop_id)){
            //     return json_ok([],1,'无效的店铺ID');
            // }
            $data=$this->request->param();
            $result=PrintService::SearchOrderDetail($data,4);
            //var_dump($result);
            if(array_key_exists('total',$result)){
                if($result['total']>0){
                    return json_ok($result,0);
                }else{
                    return json_ok([],0);
                }
            }else{
                return json_ok([],0);
            }
        }
    }
    /**
     * @todo 修改收货地址
     * @author YangFan
     */
    public function UpdateOrderArea(){
        if($this->request->ispost()){
            $user=request()->user;//登录信息
            $shop_id = empty($user['id'])?0:$user['id'];//店铺ID
            if(empty($shop_id) || !is_numeric($shop_id)){
                return json_ok([],1,'无效的店铺ID');
            }
            $data=$this->request->param();
            if (empty($data["transaction_id"])){
                return json_ok([],1,'订单号为空');
            }
            $data['area']=$data["area"];
            $data['city']=$data["city"];
            $data['province']=$data["province"];
            $data['town']=$data["town"];
            $data['address']=$data["address"];
            $data["to_area"]=$data['province']." ".$data['city']." ". $data['area']." ".$data['town']." ".$data['address'];
            $result=PrintService::UpdateOrderArea($data["transaction_id"],$data["to_area"],$data);
            if($result){
                return json_ok("更新成功",0);
            }else{
                return json_ok("更新失败",1);
            }
            
        }
    }
}


